//
//  HotBrandTableViewCell.m
//  UIHomeWork19_汽车之家找车页
//
//  Created by tusm on 16/8/10.
//  Copyright © 2016年 tusm. All rights reserved.
//

#import "HotBrandTableViewCell.h"
#import "HotBrandCollectionViewCell.h"
#define kHotBrandCollectionCell @"HotBrandCollectionCellIdentifier"


@interface HotBrandTableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation HotBrandTableViewCell
- (void)setHotBrandArray:(NSMutableArray<HotBrandList *> *)hotBrandArray {
    _hotBrandArray = hotBrandArray;
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
        flowLayOut.itemSize = CGSizeMake(50, 90);
//        flowLayOut.minimumInteritemSpacing = 8;
//        flowLayOut.minimumLineSpacing = 4;
        _collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayOut];
        [_collectionView registerClass:[HotBrandCollectionViewCell class] forCellWithReuseIdentifier:kHotBrandCollectionCell];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
    }
    return _collectionView;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        NSLog(@"%@", NSStringFromCGRect(self.contentView.bounds));
        [self.contentView addSubview:self.collectionView];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _hotBrandArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HotBrandCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kHotBrandCollectionCell forIndexPath:indexPath];
    cell.hotBrandList = self.hotBrandArray[indexPath.row];
    return cell;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = self.contentView.bounds;
    //    [_collectionView reloadData];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
